package cn.com.xy.sms.sdk.ui.config;

import org.json.JSONArray;
import org.json.JSONObject;

import cn.com.xy.sms.sdk.log.LogManager;
import cn.com.xy.sms.sdk.ui.popu.util.UiPartInterface;
import cn.com.xy.sms.sdk.ui.popu.util.ViewManger;
import cn.com.xy.sms.sdk.util.StringUtils;

/**
 * @author yangzhi 2016/5/18
 */
public class UIConfig {

    private static String sUiVersion = "201703091418";// ui版本号
    private static int sSupportState = 6;// 支持web菜单

    private static UiPartInterface sUiPart = ViewManger.getUiPartInterface();
    private static boolean sIsInit = false;
    
    synchronized public static String getUIVersion() {
        if(!sIsInit){
            if(sUiPart == null){
                sUiPart = ViewManger.getUiPartInterface();
            }
            sUiPart.doUiAction(ViewManger.UIPART_ACTION_INIT_UI_CONFIG, null);
            sIsInit = true;
        }

        return sUiVersion;
    }
    
    synchronized public static void setUIVersion(String version) {
        if(!StringUtils.isNull(version)){
            sUiVersion = version;
        }
    }
    
    synchronized public static void setUISuportState(int state) {
        if(state >= 0){
            sSupportState = state;
        }
    }
    
    synchronized public static int getUISuportState() {
        if(!sIsInit){
            if(sUiPart == null){
                sUiPart = ViewManger.getUiPartInterface();
            }
            sUiPart.doUiAction(ViewManger.UIPART_ACTION_INIT_UI_CONFIG, null);
            sIsInit = true;
        }

        return sSupportState;
    }

    /**
     * 获取默认支持的菜单数据
     * 
     * @return
     */
    public static JSONArray getDefaultSuportMenuData() {
        try {
            JSONArray array = new JSONArray();
            JSONObject jobj = new JSONObject();
//            JSONObject param = new JSONObject();
            jobj.put("name", "网页说明");
//            param.put("type", "WEB_ABOUT");
            jobj.put("action_data", "7B2274797065223A225745425F41424F5554227D");
            array.put(jobj);

//            param = new JSONObject();
            jobj = new JSONObject();
            jobj.put("name", "刷新");
            jobj.put("web_menu_type", "WM_RELOAD");
            jobj.put("action_data", "7B7D");
            array.put(jobj);

            return array;
        } catch (Throwable t) {
            LogManager.e(
                    "xiaoyuan",
                    "OnlineUpdateCycleConfig getSuportMenuDataById："
                            + t.getMessage(), t);
        }
        return null;
    }

}
